package com.zxh.Utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateUtil {
	private final static Configuration configuration = new Configuration().configure();
    private final static ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    private final static SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    private HibernateUtil() {
    }

    public static Session getSession() {
        return sessionFactory.openSession();
    }

    private static class SingletonHolder {
        private final static HibernateUtil INSTANCE = new HibernateUtil();
    }

    public static HibernateUtil getInstance() {
        return SingletonHolder.INSTANCE;
    }
}